package com.augurit.wf.common.dao;

import java.util.Calendar;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.augurit.common.base.dao.BaseDao;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.wf.app.doccode.web.form.OaDocCodeForm;
import com.augurit.wf.common.entity.OaDocCode;

@Repository
public class OaDocCodeDao extends BaseDao<OaDocCode, Long> {
	
	/**
	 * 获取最大号
	 * @param year
	 * @return
	 */
	public Long getMaxSeq(String fileCode){
		Long maxSeq = null;
		if(StringUtils.isNotBlank(fileCode)){
			String hql = "select max(ps.seq) from OaDocCode ps where ps.year= '" + getCurrentYear() +"'"
				+" and ps.word='" + fileCode + "'";
			List<Long> list = this.find(hql);
			if(list != null && list.size()>0){
				maxSeq = list.get(0);
				if(maxSeq == null)
					maxSeq = 0L;
			}else
				maxSeq = 0L;
		}
		return maxSeq;
	}
	
	
	
	/**
	 * 获取当前的年份
	 * @return
	 */
	public String getCurrentYear(){
		Calendar calendar = Calendar.getInstance();
		int year = calendar.get(Calendar.YEAR);
		return "〔" +  year + "〕";
	}

	public List<OaDocCode> CreateNoByTemplate(String template){
		List<OaDocCode> list = null;
		if(template != null && template.trim().length()>0){
			String year = getCurrentYear();
			String hql = "from OaDocCode ps where ps.template=? and ps.year=?";
			list = this.find(hql, template, year);
		}
		return list;
	}
}